﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using KioskViewerBLL.BLLObjects;

public partial class BKSelectCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }

    protected string generateSelectCategoryTable()
    {
        if (ViewState["generateSelectCategoryTable"] == null)
        {
            IList<CategoryObj> categories = KioskViewerDAL.DataObjects.DataAccess.ICategoryDao.GetAll_category();
            ViewState["generateSelectCategoryTable"] = generateDynamicTable(3, categories, "width: 100%;text-align: center;", "text-align: center; width: 20%");
        }
        //Microsoft.SqlServer.Server.        
        return (string)ViewState["generateSelectCategoryTable"];
    }

    //protected int CategoryId
    //{
    //    get { return (int)ViewState["BGCategoryId"]; }
    //    set { ViewState["BGCategoryId"] = value; }
    //}

    private string generateDynamicTable(int noCol, IList<CategoryObj> categories, string tblStyle, string cellStyle)
    {
        StringBuilder dTable = new StringBuilder(string.Format("<table style='{0}'>", tblStyle));

        // how many rows
        int noRows = ((categories.Count - 1) / noCol) - 1;
        if (noRows < 0) noRows = 0;

        int cellCount = 0;

        for (int currentRow = 0; currentRow <= noRows; currentRow++)
        {
            dTable.Append("<tr>");
            for (int currentCol = 0; currentCol <= noCol; currentCol++)
            {
                dTable.Append(string.Format("<td style=''>", cellStyle));                
                if (cellCount <= categories.Count)
                {
                    try
                    {
                        //dTable.Append(string.Format("current Row: {0}; current col {1}", currentRow, currentCol));
                        //dTable.Append(string.Format("cell: {0}; current col {1}", cellCount, (currentRow * noCol) + currentCol));
                        CategoryObj currentCategories = (CategoryObj)categories[cellCount];
                        //String stringFlash = Common.FlashObj.Replace("%%Label%%", "Song").Replace("%%Link%%", "http://localhost:4792/KioskViewer/BKMainCategory.aspx");            
                        String stringFlash = Common.FlashObj.Replace("%%Label%%", currentCategories.Flash_label).Replace("%%Link%%", currentCategories.Goto_url);
                        dTable.Append(stringFlash);
                    }
                    catch { }
                }
                dTable.Append("</td>");
                cellCount += 1;
                
            }
            dTable.Append("</tr>");
        }
        return dTable.Append("</table>").ToString();
    }
}
